<script type="text/javascript">
<!--
function toggleBox(szDivID, iState) // 1 visible, 0 hidden
{


    if(document.getElementById)	  //gecko(NN6) + IE 5+
    {
        var obj = document.getElementById(szDivID);
        //obj.style.display = iState ? "block" : "none";
		if (obj.style.display == 'block')
		{
			obj.style.display = 'none';
		}
		else
		{
			obj.style.display = 'block';
		}
    }
// not tested!
    else if(document.layers)	   //NN4+
    {
       document.layers[szDivID].visibility = iState ? "show" : "hide";
    }
// not tested
    else if(document.all)	// IE 4
    {
        document.all[szDivID].style.visibility = iState ? "visible" : "hidden";
    }
}
// -->
</script>


<h2>Sync with Milestones</h2>

<h3>Potential Sprints</h3>
<% for milestone in @milestones_missing_sprints %>
	<%=milestone.name %> 
	<a href="#" onClick="toggleBox('generate_sprint_from_milestone_<%= h(milestone.name)%>',1); return false;">Create Sprint</a>
	<%
	@sprint = Sprint.new
	@sprint.name = milestone.name
	@sprint.number_of_days = 15
	%> 
	<div id="generate_sprint_from_milestone_<%= h(milestone.name)%>" style="display:none">
	<%= start_form_tag(:controller => 'sprints', :action => 'create') %>
	<%= render_partial "form" %>
	<input type="submit" name="submit" value="Generate New Sprint"> 
	<%= end_form_tag %>
	</div>
	</div>
	<br/>

<% end %>

<% if @milestones_missing_sprints.empty? %>
	All milestones have matching sprints!
<% end %>


<h3>Sprints missing Milestones</h3>
<% for sprint in @sprints_missing_milestones %>
	<%=sprint.name %> <%= link_to('Delete', {:controller => 'sprints', :action => 'destroy', :id=>sprint.id}, :confirm => 'Are you sure?') %> 
	
	<% if !@milestones_missing_sprints.empty? %>
		<%= start_form_tag(:controller => 'sprints', :action => 'update', :id=>sprint.id) %>
		<input type=hidden name='sprint[id]', value='<%=sprint.id%>'>
		<div class="form-element">
		 * <label for="sprint_name">Pick Milestone</label>
		  <%= select 'sprint', 'name' , @milestones_missing_sprints.collect {|m| [ m.name, m.name ] } %> <input type="submit" name="submit" value="Select Milestone"> 
		</div>
		<%= end_form_tag %>
	<% end %>	
	<br/>
<% end %>

<% if @sprints_missing_milestones.empty? %>
	All sprints have matching milestones!
<% else %>
	<% if @milestones_missing_sprints.empty? %>
		Please contact your Trac admin to generate a milestone to match your sprints.
	<% end %>
<% end %>